<template>
	<view class="page px22">
		<view class=" flex bgWhite flex-between align-center br10 px30 py40 border-box" @click="chanegAvatar">
			<text>头像</text>
			<image mode="aspectFill" style="width: 100rpx;height: 100rpx;border-radius: 50%;" :src="data.wxPhotoURL?data.wxPhotoURL:'/static/index/avatar.png'"></image>
		</view>
		<view class=" flex bgWhite flex-between align-center br10 px30 py40 border-box">
			<text>姓名</text>
			<text>{{data.truename}}</text>
		</view>

		<view v-if="userInfo.identity_type == 0"
			class=" flex mt20 bgWhite flex-between align-center br10 px30 py40 border-box">
			<text>生产主体</text>
			<text>{{data.main_name}}</text>
		</view>

		<view v-if="userInfo.identity_type == 1"
			class=" flex mt20 bgWhite flex-between align-center br10 px30 py40 border-box">
			<text>所在市</text>
			<text>{{data.city_name}}</text>
		</view>
		<view v-if="userInfo.identity_type !== 1"
			class=" flex mt20 bgWhite flex-between align-center br10 px30 py40 border-box">
			<text>所在镇</text>
			<text>{{data.county_name}}</text>
		</view>

		<view v-if="userInfo.identity_type == 4"
			class=" flex mt20 bgWhite flex-between align-center br10 px30 py40 border-box">
			<text>所在村</text>
			<text>{{data.village_name}}</text>
		</view>

		<view class=" flex mt20 bgWhite flex-between align-center br10 px30 py40 border-box">
			<text>联系方式</text>
			<text>{{data.phoneNumber}}</text>
		</view>



		<view v-if="userInfo.identity_type == 4"
			class=" flex mt20 bgWhite flex-between align-center br10 px30 py40 border-box">
			<text>职位</text>
			<text>{{data.work}}</text>
		</view>

		<view v-if="userInfo.identity_type == 4"
			class=" flex mt20 bgWhite flex-between align-center br10 px30 py40 border-box">
			<text>风险等级</text>
			<text v-if="data.fx_level == 0">暂无</text>
			<text v-if="data.fx_level == 1">A级风险</text>
			<text v-if="data.fx_level == 2">B级风险</text>
			<text v-if="data.fx_level == 3">C级风险</text>
		</view>
		<view class=" flex mt20 bgWhite flex-between align-center br10 px30 py40 border-box">
			<text>剩余分数</text>
			<text>{{data.leave_score}}</text>
		</view>

		<view @click="loginOut" class="flex   mt94 flex-center align-center br83 btnBg"
			style="background: #fa3534; height:90rpx;bottom:30rpx; left:22rpx; right:22rpx; position: fixed;">
			<text :style="{color: '#fff'}">退出登录</text>
		</view>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex'
	export default {
		data() {
			return {
				data: {},
				addressList: []
			}
		},
		async onLoad() {
			await this.getData()
			if (this.addressList.length == 0) {
				this.addressList = await this.$store.dispatch('address/getAddress')
			} else {
				this.addressList = this.$store.state.address.addressList
			}
		},
		computed: {
			...mapState({
				userInfo: (state) => state.identity.userInfo
			})
		},
		methods: {
			getData() {
				return new Promise(resolve => {
					this.$http({
						url: '/Data/user_info'
					}).then(res => {
						this.data = res.data
						resolve('res.data')
					})
				})

			},
			loginOut() {
				uni.removeStorageSync('identity')
				uni.removeStorageSync('userInfo')
				uni.removeStorageSync('token')
				uni.showToast({
					title: "退出成功"
				})
				setTimeout(() => {
					uni.reLaunch({
						url: '/pages/index/index'
					})
				}, 300)
			},
			chanegAvatar(){
				uni.chooseImage({
					count:1,
					success:res=>{
						uni.uploadFile({
							url: 'https://scnongan.cn/api/ajax/upload',
							filePath: res.tempFilePaths[0],
							name: 'file',
							formData: {
								'file': res.tempFilePaths[0]
							},
							success: (uploadFileRes) => {
								let file = JSON.parse(uploadFileRes.data).data.file
								file.url = "https://scnongan.cn" + file.url
								this.getData()
								this.$http({
									url:'/Data/edit_avator',
									data:{
										wxPhotoURL:file.full_url
									}
								})
							},
						});
					}
				})
			}
		}
	}
</script>

<style>

</style>